package com.project.thread.demo;

import java.util.concurrent.*;

public class Client {

    /**
     * 核心线程数
     */
    private static final int COREPOOLSIZE = 3;

    /**
     * 最大线程数
     */
    private static final int MAXIMUMPOOLSIZE = 6;
    /**
     * 空闲线程存活时长
     */
    private static final int keepAliveTime = 50;

    /**
     * 存活市场单位
     */
    private static final TimeUnit unit = TimeUnit.MILLISECONDS;

    public static void main(String[] args) throws InterruptedException {
//        MyThreadOne one = new MyThreadOne("线程1");
//        MyThreadOne two = new MyThreadOne("线程2");
//        Thread t1 = new Thread(one);
//        Thread t2 = new Thread(two);
//        t1.start();
//        t2.start();
//
//        MyThreadTwo m1 = new MyThreadTwo("线程3");
//        MyThreadTwo m2 = new MyThreadTwo("线程4");
//        m1.start();
//        m2.start();
//
//        MyThreadThree<Object> m3 = new MyThreadThree<Object>();
//        FutureTask<Object> futureTask = new FutureTask<>(m3);
//        Thread t3 = new Thread(futureTask);
//        System.out.println("callback线程：" + Thread.currentThread().getName());
//        t3.start();


//        ExecutorService pool = Executors.newFixedThreadPool(5);
//        ExecutorService pool1 = Executors.newCachedThreadPool();
//        ExecutorService pool2 = Executors.newSingleThreadExecutor();
//        ScheduledExecutorService pool3 = Executors.newScheduledThreadPool(5);
//        pool3.scheduleAtFixedRate(() -> System.out.println("延迟一秒后没三秒执行一次"),1,3,TimeUnit.SECONDS);

//        for (int i = 0; i < 10; i++) {
//            MyThreadFour m = new MyThreadFour();
//            pool.execute(m);
//        }
//
//        for (int i = 0; i < 10;i++) {
//            MyThreadFour m = new MyThreadFour();
//            pool1.execute(m);
//        }
//
//        for (int i = 0; i < 10;i++) {
//            MyThreadFour m = new MyThreadFour();
//            pool2.execute(m);
//        }

//        for (int i = 0; i < 10;i++) {
//            MyThreadFour m = new MyThreadFour();
//            pool3.execute(m);
//        }
//        pool2.shutdown();
//        pool3.shutdown();
//        pool1.shutdown();
//        pool.shutdown();

        RejectedExecutionHandler policy = new ThreadPoolExecutor.CallerRunsPolicy();


        BlockingQueue<Runnable> bq = new LinkedBlockingQueue<>();
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(2, 3, 50, TimeUnit.MILLISECONDS, bq, policy);

        //创建三个任务
        for (int i = 0;i<20;i++){
            tpe.execute(new MyThreadOne("线程: " + i));
        }
//        Runnable t1 = new MyThreadOne("线程A");
//        Runnable t2 = new MyThreadOne("线程B");
//        Runnable t3 = new MyThreadOne("线程C");
//        Runnable t4 = new MyThreadOne("线程D");
//        Runnable t5 = new MyThreadOne("线程E");
//        Runnable t6 = new MyThreadOne("线程F");
//
//        tpe.execute(t1);
//        tpe.execute(t2);
//        tpe.execute(t3);
//        tpe.execute(t4);
//        tpe.execute(t5);
//        tpe.execute(t6);

        tpe.shutdown();

    }
}
